#include <iostream>
#include <string>

using namespace std;
int main()
{
    string input_string, list_string[3], word;
    getline(cin, input_string);
    bool flag_wrong = false, f1 = true;
    int count_space = 0, number = 0;
    char symbol;

    for (int i = 0; i < input_string.size(); i++){
        symbol = input_string[i];
        if (symbol == ' '){
                list_string[count_space] = word;
                word.clear();
                count_space += 1;
                if (count_space > 2){
                    flag_wrong = true;
                    break;
                }
        }
        else if (symbol == 0 or symbol == 1 or symbol == 2 or symbol == 3 or symbol == 4 or symbol == 5 or
                 symbol == 6 or symbol == 7 or symbol == 8 or symbol == 9){
                    flag_wrong = true;
                    break;
                 }

        else{
            word += symbol;
        }
    }
    list_string[2] = word;
    if (count_space < 2){
        flag_wrong = true;
    }
    if (flag_wrong) {
        cout << "Wrong input";
    }
    else{
        for (int i = 0; i < 3; i++){
            number *= 10;
            if (list_string[i] == "zero"){
                continue;
            }
            else if (list_string[i] == "one"){
                number += 1;
            }
            else if (list_string[i] == "two"){
                number += 2;
            }
            else if (list_string[i] == "three"){
                number += 3;
            }
            else if (list_string[i] == "four"){
                number += 4;
            }
            else if (list_string[i] == "five"){
                number += 5;
            }
            else if (list_string[i] == "six"){
                number += 6;
            }
            else if (list_string[i] == "seven"){
                number += 7;
            }
            else if (list_string[i] == "eight"){
                number += 8;
            }
            else if (list_string[i] == "nine"){
                number += 9;
            }
            else{
                f1 = false;
                cout << "Wrong input";
                break;
            }
        }
        if (f1){
            int a = number, b = number;
            char f;
            for (int k = 0; k < number; k++){
                f = true;
                for (int j = 2; j < a; j++){
                    if (a % j == 0){
                        f = false;
                        break;
                    }
                }
                if (f) {cout << a;
                break;}
                f = true;
                for (int j = 2; j < b; j++){
                    if (b % j == 0){
                        f = false;
                        break;
                    }
                }
                if (f) {cout << b;
                break;}
                a += 1;
                b -= 1;
                }
        }

    }
}
